<template>
	<view>
	    <view>
	        <view class='header'>
	            <image src='/static/images/wechat-circle.png'></image>
	        </view>
	       
			<view class="btnBox">
				<u-button type="success" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">获取你的微信手机号码</u-button>
				<!-- <view class="btn" @click="login()">获取你的手机号码</view> -->
			</view>
	    </view>
	</view>

</template>

<script>
	import {bindPhone} from "@/api/api"
	export default {
		data() {
			return {
				user_id:0,
				session_key:''
			}
		},
		onLoad: function (option) {
			  this.user_id = option.user_id
			  this.session_key = option.session_key
		},
		
		methods:{
			getPhoneNumber(e){
				if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
					uni.showToast({
						title: '获取手机号失败',
						icon: 'none',
					});
					return false;
				}
				
				var data = {
					user_id: this.user_id,
					session_key:this.session_key,
					iv: e.detail.iv,
					encryptedData: e.detail.encryptedData
				}
				
				bindPhone(data).then(res=>{
					uni.showToast({
						title: res.msg,
						icon: 'none',
					});
					uni.setStorageSync('login_back',true)
					setTimeout(function(){
						uni.navigateBack({//返回
						      delta: 2
						    })
						// uni.switchTab({
						//     url: '/pages/me/index'
						//   })
					},1500)
				})
			}
		}
	}
</script>
<style>
	page{background-color: #F5F5F5;}
</style>
<style scoped>
	.header {
	  margin: 90rpx 0 90rpx 50rpx;
	  border-bottom: 1px solid #ccc;
	  text-align: center;
	  width: 650rpx;
	  height: 300rpx;
	  line-height: 450rpx;
	}
	
	.header image {
	  width: 200rpx;
	  height: 200rpx;
	}
	
	.content {
	  margin-left: 50rpx;
	  margin-bottom: 90rpx;
	}
	
	.content text {
	  display: block;
	  color: #9d9d9d;
	  margin-top: 40rpx;
	}
	
	.btn{width: 600rpx;height: 80rpx;background: #07c160;margin-top: 50rpx;
	line-height: 80rpx;text-align: center;border-radius: 100rpx;
	color: #ffffff;font-size: 35rpx;font-weight: bold;letter-spacing: 10rpx;
	}
	.btnBox{display: flex;justify-content: center;width: 100%;}
</style>